package GUI;

import interpreter.ShapeBase;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.border.Border;

/** Panel with interpreted shapes radiobutons */
@SuppressWarnings("serial")
public class ShapesPanel extends JPanel implements ActionListener{
	/** Current choosen shape */
	public static String currentShape;
	
	/** Create panel */
	public ShapesPanel(ShapeBase shapeBase){
		// One row one column
		setLayout(new GridLayout(1, 1));
		Border border = BorderFactory.createTitledBorder("Shapes");
		setBorder(border);
		
		ButtonGroup group = new ButtonGroup();
		// Shapes buttons
		boolean defaultB = false;
		for (int i = 0; i < shapeBase.get_shape_list().size() ; i++){
			JRadioButton tmpRadioB = new JRadioButton(shapeBase.get_shape_list().get(i).getName());
			add(tmpRadioB);
			group.add(tmpRadioB);
			tmpRadioB.addActionListener(this);
			
			if(!defaultB){
				tmpRadioB.setSelected(true);
				currentShape = tmpRadioB.getText();
			}
		}		
	}
	
    /** Listens to the radio button change. */
	public void actionPerformed(ActionEvent e) {
		currentShape = e.getActionCommand();
	}
}